package com.zshan.clinic.web.controller.stock;


import com.zshan.clinic.admin.entity.vo.StockDrugDetailVo;
import com.zshan.clinic.admin.entity.vo.StockDrugTransVo;
import com.zshan.clinic.admin.service.stock.StockDrugService;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 库存管理
 */
@RestController
@RequestMapping("/stock/drug")
public class StockDrugController extends AbstractController {


    @Autowired
    private StockDrugService stockDrugService;


    /**
     * 查询药品库存明细
     * @param drugId 药品ID
     * @param storageId 库房ID
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getStockDrugDetailList")
    public RestResp<PageInfo<StockDrugDetailVo>> getStockDrugDetailList(@RequestParam(name = "drugId") Long drugId,
                                                                        @RequestParam(name = "storageId") Long storageId,
                                                                        @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                        @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StockDrugDetailVo> detailList = stockDrugService.getStockDrugDetailList(userInfo.getClinicId(), drugId,storageId, pageNo, pageSize);
        return RestResp.SUCCESS(detailList);
    }

    /**
     * 查询药品库存流水
     * @param drugId 药品ID
     * @param storageId 库房ID
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getStockDrugTransList")
    public RestResp<PageInfo<StockDrugTransVo>> getStockDrugTransList(@RequestParam(name = "drugId") Long drugId,
                                                                        @RequestParam(name = "storageId") Long storageId,
                                                                        @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                        @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StockDrugTransVo> detailList = stockDrugService.getStockDrugTransList(userInfo.getClinicId(), drugId,storageId, pageNo, pageSize);
        return RestResp.SUCCESS(detailList);
    }
}
